<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html;charset=utf-8" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户登录 - 新华每日新闻</title>
    <style>
        /* 基础样式 */
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }

        body {
            font-family: "Microsoft YaHei", sans-serif;
            color: #333;
            line-height: 1.6;
            background-color: #f5f5f5;
        }

        /* 头部样式 */
        .news-header {
            background-color: #fff;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
            padding: 15px 20px;
        }

        .site-name {
            color: #c00;
            font-size: 28px;
            font-weight: bold;
        }

        /* 登录容器 */
        .login-container {
            max-width: 500px;
            margin: 50px auto;
            padding: 30px;
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }

        .login-title {
            color: #c00;
            font-size: 24px;
            margin-bottom: 30px;
            text-align: center;
            padding-bottom: 10px;
            border-bottom: 2px solid #c00;
        }

        /* 表单样式 */
        .form-group {
            margin-bottom: 20px;
        }

        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: bold;
        }

        .form-control {
            width: 100%;
            padding: 12px 15px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 16px;
            transition: border-color 0.3s;
        }

        .form-control:focus {
            border-color: #c00;
            outline: none;
        }

        /* 登录按钮 */
        .login-submit {
            width: 100%;
            padding: 12px;
            background-color: #c00;
            color: white;
            border: none;
            border-radius: 4px;
            font-size: 16px;
            font-weight: bold;
            cursor: pointer;
            transition: background-color 0.3s;
        }

        .login-submit:hover {
            background-color: #a00;
        }

        /* 辅助链接 */
        .login-links {
            margin-top: 20px;
            text-align: center;
        }

        .login-links a {
            color: #666;
            margin: 0 10px;
            text-decoration: none;
            transition: color 0.3s;
        }

        .login-links a:hover {
            color: #c00;
        }

        /* 响应式设计 */
        @media (max-width: 600px) {
            .login-container {
                margin: 20px;
                padding: 20px;
            }
        }

        button.login-btn {
            padding: 8px 15px;
            background-color: #c00;
            color: white;
            border: none;
            cursor: pointer;
        }
    </style>
</head>
<body>
<!-- 头部区域 -->
<header class="news-header">
    <h1 class="site-name">新华每日新闻</h1>
    <button onclick="window.location.replace(document.referrer);" class="login-btn">返回</button>
</header>

<!-- 登录表单区域 -->
<div class="login-container">
    <h2 class="login-title">用户登录</h2>

    <form method="post">
        <div class="form-group">
            <label for="username">用户名</label>
            <input type="text" id="username" name="username" class="form-control" placeholder="请输入用户名" required>
        </div>

        <div class="form-group">
            <label for="password">密码</label>
            <input type="password" id="password" name="password" class="form-control" placeholder="请输入密码" required>
        </div>

        <div class="form-group">
            <button type="button" class="login-submit">登录</button>
        </div>

        <div class="login-links">
            <a href="#">忘记密码?</a>
            <a href="#">注册新账号</a>
        </div>
    </form>
</div>
<script src="<c:url value="/resources/js/jquery-3.7.1.min.js"/>"></script>
<script>
    $("button[type='button']").on("click", function () {
        $(document).ready(function () {
            $.ajax({
                url: "/page/login",
                method: 'post',
                data: {
                    username: $("input[name='username']").val(),
                    password: $("input[name='password']").val()
                },
                success: function (data) {
                    if (data === 0) {
                        alert("用户名或密码错误");
                    } else if (data === 1 || data === 2 || data === 3) {
                        location.replace(document.referrer);
                    } else if (data === -1) {
                        alert("你的账号已被禁用，请联系管理员")
                    }
                },
                error: function (error) {
                }
            });
        });
    });
</script>
</body>
</html>
